using System;
using System.Collections;
using System.ComponentModel.Design;
using Fcdbas.WinUI.Windows;
namespace Fcdbas.WinUI.Design
{
	internal class SalNamedPropertiesEditor : CollectionEditor
	{
		internal class EditableEntry
		{
			private string m_name;
			private string m_value;
			public string Name
			{
				get
				{
					return this.m_name;
				}
				set
				{
					this.m_name = value;
				}
			}
			public string Value
			{
				get
				{
					return this.m_value;
				}
				set
				{
					this.m_value = value;
				}
			}
			public EditableEntry(string name, string value)
			{
				this.m_name = name;
				this.m_value = value;
			}
		}
		private int newCounter;
		public SalNamedPropertiesEditor(System.Type type) : base(type)
		{
		}
		protected override CollectionEditor.CollectionForm CreateCollectionForm()
		{
			CollectionEditor.CollectionForm collectionForm = base.CreateCollectionForm();
			collectionForm.Text = "Named Properties Editor";
			return collectionForm;
		}
		protected override System.Type CreateCollectionItemType()
		{
			return typeof(SalNamedPropertiesEditor.EditableEntry);
		}
		protected override object CreateInstance(System.Type itemType)
		{
			this.newCounter++;
			return new SalNamedPropertiesEditor.EditableEntry("Name" + this.newCounter, "Value");
		}
		protected override object[] GetItems(object editValue)
		{
			SalNamedProperties salNamedProperties = SalNamedPropertiesEditor.SafeCast(editValue);
			int num = 0;
			object[] array = new object[salNamedProperties.Count];
			System.Collections.ArrayList arrayList = new System.Collections.ArrayList(salNamedProperties.Keys);
			arrayList.Sort();
			foreach (string text in arrayList)
			{
				array[num++] = new SalNamedPropertiesEditor.EditableEntry(text, salNamedProperties[text]);
				if (text.StartsWith("Name") && text.Length > 4)
				{
					int val = 0;
					if (int.TryParse(text.Substring(4), out val))
					{
						this.newCounter = System.Math.Max(this.newCounter, val);
					}
				}
			}
			return array;
		}
		protected override object SetItems(object editValue, object[] value)
		{
			SalNamedProperties salNamedProperties = SalNamedPropertiesEditor.SafeCast(editValue);
			salNamedProperties.Clear();
			for (int i = 0; i < value.Length; i++)
			{
				SalNamedPropertiesEditor.EditableEntry editableEntry = (SalNamedPropertiesEditor.EditableEntry)value[i];
				salNamedProperties.Add(editableEntry.Name, editableEntry.Value);
			}
			return editValue;
		}
		internal static SalNamedProperties SafeCast(object obj)
		{
			SalNamedProperties result;
			try
			{
				SalNamedProperties salNamedProperties = (SalNamedProperties)obj;
				result = salNamedProperties;
			}
			catch (System.InvalidCastException)
			{
				if (obj.GetType().Name == "SalNamedProperties")
				{
					throw new System.InvalidCastException("The cast to SalNamedProperty has failed because there are two instances of the PPJ.Runtime assembly currently loaded in memory.\nThis is a known bug in Visual Studio .NET when using the designer with assemblies referenced using CopyLocal = True.");
				}
				throw;
			}
			return result;
		}
	}
}
